// 合并添加对象
export const pick = function (array, obj) {
  const pick = {};
  for (let i = 0; i < array.length; i++) {
    for (const key in obj) {
      if (Object.hasOwnProperty.call(obj, key)) {
        if (array[i] === key) {
          pick[key] = obj[key];
        }
      }
    }
  }
  return pick;
};

// 截取字符串
export const substr = function (str = "", index, start = 0) {
  let end = str.length - 1;
  if (index instanceof String) {
    end = str.indexOf(index);
  } else if (index instanceof Number) {
    end = index;
  }
  return str.substring(start, end);
};

// 判断属性是否为空
export const isEmptyObject = function (object) {
  let flag = true;
  for (const key in object) {
    if (
      Object.hasOwnProperty.call(object, key) ||
      object[key] == null ||
      object[key] == "" ||
      object[key] == undefined
    ) {
      flag = false;
    }
  }
  return flag;
};
// 节流
export function throttle(fn, wait, timout) {
  if (!timout) {
    return timout = setTimeout(() => {
      fn.apply(...arguments);
    }, wait || 500);
  }
}
